import * as Blockly from 'blockly';

// 将工作区状态保存到本地存储
export function save(workspace: Blockly.WorkspaceSvg): void {
  const data = Blockly.serialization.workspaces.save(workspace);
  localStorage.setItem('blocklyWorkspace', JSON.stringify(data));
}

// 从本地存储加载工作区状态
export function load(workspace: Blockly.WorkspaceSvg): void {
  const data = localStorage.getItem('blocklyWorkspace');
  if (data) {
    try {
      const json = JSON.parse(data);
      Blockly.serialization.workspaces.load(json, workspace);
    } catch (e) {
      console.error('加载工作区时出错:', e);
    }
  }
}
